package com.application.sistercityapplication.listadapter;

import java.util.List;

import com.application.sistercityapplication.dto.NewsDto;
import com.application.sistercityapplication.main.R;
import com.squareup.picasso.Picasso;


import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class NewsAdapter extends BaseAdapter {

	private Context context;
	private final List<NewsDto> news;
	public Activity magazineBookSportMainActivity;

	public NewsAdapter(Context context, List<NewsDto> news, Activity a) {
		this.context = context;
		this.news = news;
		this.magazineBookSportMainActivity = a;
	}

	@Override
	public int getCount() {
		return news.size();
	}

	@Override
	public View getView(final int position, final View convertView,
			ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View gridView;

		if (convertView == null) {

			gridView = new View(context);
			NewsDto newsDto = news.get(position);
			// get layout from mobile.xml
			gridView = inflater.inflate(R.layout.book_item_layout, null);
			try {

				ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_cover);
				Picasso.with(context).load(newsDto.getImage_path()).into(imageView);

			} catch (Exception e) {
				// TODO: handle exception
			}

			FrameLayout bookclick = (FrameLayout) gridView.findViewById(R.id.BookClick);

		} else {
			gridView = (View) convertView;
		}

		return gridView;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return news.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	
}
